/**
 * @Author 韦建韩
 * @Date 2022/5/20
 */
package com.example.devops.web.controller.applicationAdmin;

import com.example.devops.Manage.UserManager.UserInfoManage;
import com.example.devops.dao.UserMapper;
import com.example.devops.entity.common.Result;
import com.example.devops.entity.pojo.User;
import com.example.devops.entity.pojo.UserToPermission;
import com.example.devops.exception.ValidationException;
import com.example.devops.service.impl.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("permission")
public class PermissionController {
    @Autowired
    PermissionService permissionService;
    @Autowired
    UserMapper userMapper;

    @RequestMapping("getPermission")
    public Result getPermission() {

        return permissionService.getPermission();
    }

    @RequestMapping("userToPermission")
    public Result userToPermission(@RequestBody UserToPermission userToPermission){
        User user = UserInfoManage.get();
        User user1 = userMapper.selectById(user.getId());
        if(!"17877887975".equals(user1.getAccount())){
            throw new ValidationException("你不是管理员，无法进行该操作！");
        }
        return permissionService.userToPermission(userToPermission);
    }
}
